﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Navigation;
using System.Diagnostics;
using System.Text.RegularExpressions;
using System.Windows.Markup;
// ColorPicker, Copyright Mirosław M. Mączka.  All Rights Reserved. This code released under the terms of the Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.)

namespace ColorPicker
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {

        private UCbutton getButtonFromSender(object sender)
        {
            MenuItem mi = sender as MenuItem;
            if (null != mi)
            {
                ContextMenu cm = mi.Parent as ContextMenu;
                if (null != cm)
                {
                    return cm.PlacementTarget as UCbutton;
                }
            }
            return null;
        }

        private bool getStringFromColor(object sender, ColorKind ck, OutputFormat of)
        {
            UCbutton b = getButtonFromSender(sender);
            if (null == b) return false;
            //
            ColorsCooked cc = b.EssentialColor;
            if (null == cc) return false;
            //
            List<ColorsCooked> lck = new List<ColorsCooked>();
                    //enum ColorKind :int{ Usual = 0, Complement = 1, Monochrome = 2, Triadic = 3, Analogous=4,SplitComplements=5 };

            add2LckColor(lck, cc, (int)ck);
            //
            if (inGradient)
            {
                if (ccGradient.Count > 100) return false;//pomyłka?
                ccGradient.AddRange(lck);
                return true;
            }
            //
            string s = lck2String(lck, of);
            if ("" == s) return false;

            Clipboard.SetText(s, TextDataFormat.UnicodeText);
            return true;
        }
        private void MenuItem_CS_Click(object sender, RoutedEventArgs e)
        {
            getStringFromColor(sender, ColorKind.Usual, OutputFormat.CS);
        }
        private void MenuItem_XAML_Color_Click(object sender, RoutedEventArgs e)
        {
            getStringFromColor(sender, ColorKind.Usual, OutputFormat.ColorXAML);
        }
        private void MenuItem_XAML_Brush_Click(object sender, RoutedEventArgs e)
        {
            getStringFromColor(sender, ColorKind.Usual, OutputFormat.BrushXAML);
        }
        private void MenuItem_HTML_Color_Click(object sender, RoutedEventArgs e)
        {
            getStringFromColor(sender, ColorKind.Usual, OutputFormat.ColorHTML);
        }


        private void MenuItem_XAML_Complement_Click(object sender, RoutedEventArgs e)
        {
            getStringFromColor(sender, ColorKind.Complement, OutputFormat.FromKbd);
        }
        private void MenuItem_XAML_Monochrome_Click(object sender, RoutedEventArgs e)
        {
            getStringFromColor(sender, ColorKind.Monochrome, OutputFormat.FromKbd);
        }
        private void MenuItem_XAML_Triadic_Click(object sender, RoutedEventArgs e)
        {
            getStringFromColor(sender, ColorKind.Triadic, OutputFormat.FromKbd);
        }
        private void MenuItem_XAML_Analogous_Click(object sender, RoutedEventArgs e)
        {
            getStringFromColor(sender, ColorKind.Analogous, OutputFormat.FromKbd);
        }
        private void MenuItem_XAML_Split_Complements_Click(object sender, RoutedEventArgs e)
        {
            getStringFromColor(sender, ColorKind.SplitComplements, OutputFormat.FromKbd);
        }

    }//class
}//namespace
